<template>
	<div id="two">
		<h1>two</h1>
		<p>非父子组件传值：{{value}}</p>
	</div>
</template>

<script>
//import center from "./center.js"

export default {
	data(){
		return {
			value: ""
		}
	},
	methods:{
		//该函数用于事件监听和移除监听中
		getVal(value){
			console.log("接收到了value")
			this.value = value;
		}
	},
	created(){
		//在created中
		//监听事件 接收数据
		this.center.$on("passEvent",this.getVal)
		this.center.$on("passEvent",()=>{
			console.log("触发了监听")
		})
	},
	beforeDestroy(){
		//在beforeDestroy中
		//移除事件监听
		this.center.$off("passEvent",this.getVal)
	}
}

</script>

<style>
#two{
	padding: 20px;
	background: darkmagenta;
	border: 2px solid #000000;
}
</style>